package com.atguigu.tingshu.album.client;

import com.atguigu.tingshu.album.mapper.BaseCategory1Mapper;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.cache.GuiguCache;
import com.atguigu.tingshu.model.album.BaseCategory1;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author GQS @Date 2024/11/5/21:12 @Description
 * 分类信息内部调用的控制层
 */
@RestController
@RequestMapping(value = "/client/album/category")
public class BaseCategoryClientController {

  @Autowired
  private BaseCategoryService baseCategoryService;

  @Autowired
  private BaseCategory1Mapper baseCategory1Mapper;

  /**
   * 查询所有的一级分类
   * @return
   */
  @GetMapping(value = "/getBaseCategory1")
  public List<BaseCategory1> getBaseCategory1(){
    return baseCategory1Mapper.selectList(null);
  }
  /**
   * 根据三级分类查询一级二级三级分类的视图
   * @param category3Id
   * @return
   */
  @GuiguCache(name = "getBaseCategoryView")
  @GetMapping(value = "/getBaseCategoryView/{category3Id}")
  public BaseCategoryView getBaseCategoryView(@PathVariable(value = "category3Id") Long category3Id){
    return baseCategoryService.getBaseCategoryView(category3Id);
  }

  /**
   * 查询指定一级分类下的前7热门的三级分类数据
   * @param category1Id
   * @return
   */
  @GuiguCache(name = "getBaseCategory3List")
  @GetMapping(value = "/getBaseCategory3List/{category1Id}")
  public List<BaseCategory3> getBaseCategory3List(@PathVariable(value = "category1Id") Long category1Id){
    return baseCategoryService.findTopBaseCategory3(category1Id);
  }

}
